package com.ipan.builder.entity;

import javax.persistence.TemporalType;

/**
 * JPA字段配置信息
 * 
 * @author iPan
 * @version 2013-11-30
 */
public class JpaColumnCfg {

	/** 实体字段名字 */
	private String columnName = "";

	/** 实体字段类型 */
	private Class<?> columnType = String.class;

	/** @Column name */
	private String name = "";

	/** @Column unique */
	private boolean unique = false;

	/** @Column nullable */
	private boolean nullable = true;

	/** @Column insertable */
	private boolean insertable = true;

	/** @Column updatable */
	private boolean updatable = true;

	/** @Column columnDefinition */
	private String columnDefinition = "";

	/** @Column table */
	private String table = "";

	/** @Column length */
	private int length = 255;

	/** @Column precision */
	private int precision = 0;

	/** @Column scale */
	private int scale = 0;
	
	/** @Build searchColumn */
	private boolean searchColumn = false;	// 查询字段
	
	/** @Build listColumn */
	private boolean listColumn = false;		// 列表字段
	
	/** @Build submitColumn */
	private boolean submitColumn = false;	// 表单提交字段
	
	/** @Build hiddenColumn */
	private boolean hiddenColumn = false;	// 表单隐藏字段
	
	/** @Build comment */
	private String comment = "";			// 数据库字段注释
	
	/** @Temporal */
	private TemporalType temporealType;		// 时间日期类型
	
	/** @Transient */
	private boolean isTransient = false; // 是否含有@Transient注解
	
	/** @OneToOne */
	private boolean isOneToOne = false; // 是否含有@OneToOne注解
	
	/** @OneToMany */
	private boolean isOneToMany = false; // 是否含有@OneToMany注解
	
	/** @ManyToOne */
	private boolean isManyToOne = false; // 是否含有@ManyToOne注解
	
	/** @ManyToMany */
	private boolean isManyToMany = false; // 是否含有@ManyToMany注解

	/** 实体类配置 */
	private JpaEntityCfg entityCfg;

	public JpaColumnCfg(JpaEntityCfg entityCfg) {
		this.entityCfg = entityCfg;
	}

	public JpaColumnCfg(JpaEntityCfg entityCfg, String columnName, Class<?> columnType) {
		this.entityCfg = entityCfg;
		this.columnName = columnName;
		this.columnType = columnType;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public Class<?> getColumnType() {
		return columnType;
	}

	public void setColumnType(Class<?> columnType) {
		this.columnType = columnType;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isUnique() {
		return unique;
	}

	public void setUnique(boolean unique) {
		this.unique = unique;
	}

	public boolean isNullable() {
		return nullable;
	}

	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	public boolean isInsertable() {
		return insertable;
	}

	public void setInsertable(boolean insertable) {
		this.insertable = insertable;
	}

	public boolean isUpdatable() {
		return updatable;
	}

	public void setUpdatable(boolean updatable) {
		this.updatable = updatable;
	}

	public String getColumnDefinition() {
		return columnDefinition;
	}

	public void setColumnDefinition(String columnDefinition) {
		this.columnDefinition = columnDefinition;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public int getPrecision() {
		return precision;
	}

	public void setPrecision(int precision) {
		this.precision = precision;
	}

	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}

	public JpaEntityCfg getEntityCfg() {
		return entityCfg;
	}

	public void setEntityCfg(JpaEntityCfg entityCfg) {
		this.entityCfg = entityCfg;
	}
	

	public boolean isSearchColumn() {
		return searchColumn;
	}

	public void setSearchColumn(boolean searchColumn) {
		this.searchColumn = searchColumn;
	}

	public boolean isListColumn() {
		return listColumn;
	}

	public void setListColumn(boolean listColumn) {
		this.listColumn = listColumn;
	}

	public boolean isSubmitColumn() {
		return submitColumn;
	}

	public void setSubmitColumn(boolean submitColumn) {
		this.submitColumn = submitColumn;
	}

	public boolean isHiddenColumn() {
		return hiddenColumn;
	}

	public void setHiddenColumn(boolean hiddenColumn) {
		this.hiddenColumn = hiddenColumn;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
	
	public TemporalType getTemporealType() {
		return temporealType;
	}

	public void setTemporealType(TemporalType temporealType) {
		this.temporealType = temporealType;
	}
	
	public boolean isDateType() {
		return java.util.Date.class.isAssignableFrom(this.columnType);
	}
	
	public boolean isTransient() {
		return isTransient;
	}

	public void setTransient(boolean isTransient) {
		this.isTransient = isTransient;
	}
	
	public boolean isOneToOne() {
		return isOneToOne;
	}

	public void setOneToOne(boolean isOneToOne) {
		this.isOneToOne = isOneToOne;
	}

	public boolean isOneToMany() {
		return isOneToMany;
	}

	public void setOneToMany(boolean isOneToMany) {
		this.isOneToMany = isOneToMany;
	}

	public boolean isManyToOne() {
		return isManyToOne;
	}

	public void setManyToOne(boolean isManyToOne) {
		this.isManyToOne = isManyToOne;
	}

	public boolean isManyToMany() {
		return isManyToMany;
	}

	public void setManyToMany(boolean isManyToMany) {
		this.isManyToMany = isManyToMany;
	}
	
	/**
	 * 是否关联字段
	 * @return true是 false否；
	 */
	public boolean isAssociateColumn() {
		return isOneToOne() || isOneToMany() || isManyToOne() || isManyToMany();
	}

	@Override
	public String toString() {
		return "JpaColumnCfg [columnName=" + columnName + ", columnType=" + columnType + ", name=" + name + ", unique=" + unique + ", nullable="
				+ nullable + ", insertable=" + insertable + ", updatable=" + updatable + ", columnDefinition=" + columnDefinition + ", table="
				+ table + ", length=" + length + ", precision=" + precision + ", scale=" + scale + ", searchColumn=" + searchColumn + ", listColumn="
				+ listColumn + ", submitColumn=" + submitColumn + ", hiddenColumn=" + hiddenColumn + ", comment=" + comment + ", temporealType="
				+ temporealType + ", isTransient=" + isTransient + ", isOneToOne=" + isOneToOne + ", isOneToMany=" + isOneToMany + ", isManyToOne="
				+ isManyToOne + ", isManyToMany=" + isManyToMany + ", entityCfg=" + entityCfg + "]";
	}

}
